package cn.linstudy.blog.handler;

import cn.linstudy.blog.enums.ErrorCodeEnum;
import cn.linstudy.blog.utils.ResponseUtils;
import cn.linstudy.blog.vo.BaseVO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

/**
 * @Author XiaoLin
 * @Date 2021/12/22 15:41
 * @Description 用户未登录处理类
 */
@Component
public class UserNotLoginHandler implements AuthenticationEntryPoint {
    /**
     * 用户未登录返回结果
     */
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) {
        ResponseUtils
            .ResponseMeg(response, new BaseVO(false, ErrorCodeEnum.NO_LOGIN_OR_COKKIE_IS_OUT_DATE.getKey(), ErrorCodeEnum.NO_LOGIN_OR_COKKIE_IS_OUT_DATE.getValue()));
    }
}